package com.gucheng.springframework.beans.factory.support;

import com.gucheng.springframework.beans.BeansException;
import com.gucheng.springframework.beans.factory.BeanFactory;
import com.gucheng.springframework.beans.factory.config.BeanDefinition;

public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements BeanFactory {

    @Override
    public Object getBean(String name) throws BeansException {
        //对单例的Bean获取
       Object bean = getSingleton(name);
       //1.1如果单例的Bean不存在，则拿到Bean的定义，进行实例化
       if (bean != null) {
           return bean;
       }
        //根据名称获取bean的定义
        BeanDefinition beanDefinition = getBeanDefinition(name);
       //创建Bean
       return createBean(name, beanDefinition);
    }

    //1.2获取Bean的定义的抽象方法
    protected abstract BeanDefinition getBeanDefinition(String beanName) throws BeansException ;

    //1.3创建Bean的抽象方法
    protected abstract Object createBean(String name, BeanDefinition beanDefinition);


}
